package com.mvp.shq.washer.ui.withdraw;

import com.mvp.shq.washer.entity.BasicInfo;
import com.mvp.shq.washer.entity.result.BaseResult;
import com.mvp.shq.washer.http.BaseObserver;
import com.mvp.shq.washer.utils.SignUtils;
import com.mvp.shq.washer.utils.SpUtil;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2017/9/5.
 */

public class Presenter extends WithDrawConstract.Presenter {
    @Override
    public void onStart() {

    }

    @Override
    void withDraw(BigDecimal money, String realName, String account) {
        String userId = SpUtil.getUser().getId();
        String token = SpUtil.getToken();
        Map<String,String> map = new HashMap();
        map.put("money",money+"");
        map.put("realName",realName);
        map.put("account",account);
        map.put("userId",userId);
        String sign = SignUtils.getSignature(map);
        model.withDraw(token,userId,money,realName,account,sign)
                .subscribe(new BaseObserver<String>(view) {
                    @Override
                    protected void onSuccees(BaseResult<String> t) throws Exception {
                        if (t.isError()){
                            view.withDrawF(t.getMsg());
                        }else {
                            view.withDrawS();
                        }
                    }

                    @Override
                    protected void onFailure(Throwable e, boolean isNetWorkError) throws Exception {
                        e.printStackTrace();
                        view.withDrawF("未知错误");
                    }
                });
    }

}
